﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Tulde.WindowsPhone.Music.Mp3Tunes;
using Tulde.WindowsPhone.Music.ViewModel;
using System.Collections.Generic;
using System.Linq;

namespace Tulde.WindowsPhone.Music
{
    public class DebugMusicServiceProvider : IMusicService
    {
        private List<Artist> CreateArtistList()
        {
            List<Artist> artists = new List<Artist>();
            Enumerable.Range(0, 25).ToList().ForEach(x =>
                {
                    artists.Add(new Artist
                    {
                         AlbumCount = 1,
                         TrackCount = 10,
                          ArtistId = Guid.NewGuid().ToString(),
                           ArtistName = "Awesome",
                           ArtistSize = "1000"
                            

                    });
                });
            return artists;
        }
        private List<Album> CreateAlbumList()
        {
            List<Album> artists = new List<Album>();
            Enumerable.Range(0, 5).ToList().ForEach(x =>
            {
                artists.Add(new Album
                {
                    AlbumId = Guid.NewGuid().ToString(),
                    TrackCount ="10",
                    AlbumTitle ="Awesome Album",
                    HasArt = 0,
                    AlbumSize = 323232232,
                    ArtistId = Guid.NewGuid().ToString(),
                    ArtistName = "Awesome",
                    


                });
            });
            return artists;
        }
        private List<Track> CreateTrackList()
        {
            List<Track> tracks = new List<Track>();
            Enumerable.Range(0, 10).ToList().ForEach(x =>
            {
                tracks.Add(new Track
                {
                     AlbumId = Guid.NewGuid().ToString(),
                     TrackId = Guid.NewGuid().ToString(),
                     TrackFileKey = Guid.NewGuid().ToString(),
                     TrackNumber = x.ToString(),
                     TrackFileName = "Track " + x,
                     TrackTitle = "Track " + x,
                     TrackFileSize = 432322,
                     AlbumTitle = "Awesome Album"
                });
            });
            return tracks;
        }
        private List<Playlist> CreatePlaylist()
        {
            List<Playlist> pl = new List<Playlist>();
            Enumerable.Range(0, 10).ToList().ForEach(x =>
            {
                pl.Add(new Playlist
                {
                    Title = "Playlist " + x  
                });
            });
            return pl;
        }

        public void Authenticate(ICredentials credentials, Action<ViewModel.AuthenticationToken> callback)
        {
            SecurityProvider.SetCredentials(credentials);
            AuthenticationService s = new AuthenticationService();

            Uri url = s.CreateServiceEndpoint(AuthenticationOperations.login, new AuthenticationServiceParameters
            {
                UserName = SecurityProvider.Credentials.UserName,
                Password = SecurityProvider.Credentials.Password
            });
            s.InvokeAsynch<AuthenticationToken>(url, callback);
        }

        public void EnumerateArtists(Action<ViewModel.ArtistCollection> callback)
        {
            callback(new ArtistCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 25,
                    Type = "artist"
                },
                Artists = this.CreateArtistList( )
            });
        }

        public void EnumerateAlbums(Action<ViewModel.AlbumCollection> callback)
        {
            callback(new AlbumCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 5,
                    Type = "album"
                },
                Albums = this.CreateAlbumList()
            });
        }

        public void EnumerateTracks(Action<ViewModel.TrackCollection> callback)
        {
            callback(new TrackCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 10,
                    Type = "track"
                },
                Tracks = this.CreateTrackList()
            });
        }

        public void EnumeratePlaylists(Action<ViewModel.PlaylistCollection> callback)
        {

            callback(new PlaylistCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 10,
                    Type = "playlist"
                },
                Playlists = this.CreatePlaylist()
            });
        }

        public void EnumerateVideos(Action<ViewModel.TrackCollection> callback)
        {
            callback(new TrackCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 10,
                    Type = "track"
                },
                Tracks = this.CreateTrackList()
            });
        }

        public void SearchArtists(string pattern, Action<ViewModel.SearchResults> callback)
        {
            throw new NotImplementedException();
        }

        public void SearchAlbums(string pattern, Action<ViewModel.SearchResults> callback)
        {
            throw new NotImplementedException();
        }

        public void SearchTracks(string pattern, Action<ViewModel.SearchResults> callback)
        {
            throw new NotImplementedException();
        }

        public void GetArtistAlbums(ViewModel.Artist artist, Action<ViewModel.AlbumCollection> callback)
        {
            callback(new AlbumCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 5,
                    Type = "album"
                },
                Albums = this.CreateAlbumList()
            });
        }

        public void GetAlbumTracks(ViewModel.Album album, Action<ViewModel.TrackCollection> callback)
        {
            callback(new TrackCollection
            {
                Summary = new ResultSummary
                {
                    TotalResults = 10,
                    Type = "track"
                },
                Tracks = this.CreateTrackList()
            });
        }

        public void GetPlaylist(ViewModel.Playlist playlist, Action<ViewModel.TrackCollection> callback)
        {
            throw new NotImplementedException();
        }

        public void GetContinousDataStream(ViewModel.Track track, Action<byte[]> callback)
        {
            throw new NotImplementedException();
        }
    }
}
